package org.llu.urldirect.base;

import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class UrlBaseTest {

    private static URLConnection httpConn;
    /**
     * CVE-2024-22259 -> http://@www.test.com[@www.baidu.com/tou
     * CVE-2024-22243 -> http://www.test.com[@www.baidu.com/tou
     */
    public static void main(String[] args) {
        String url = "http://www.evail.com/test.com";
        UriComponents uriString = UriComponentsBuilder.fromUriString(url).build(true);
//        获取协议
        String scheme = uriString.getScheme();
        String host = uriString.getHost();
        String path = uriString.getPath();
        String userInfo = uriString.getUserInfo();
        System.out.println("userInfo: " + userInfo);
        System.out.println("scheme : " + scheme);
        System.out.println("host : " + host);
        System.out.println("path : " + path);

    }


    public  void testUriComponentsBuilder(){

        UriComponents uriString =UriComponentsBuilder.fromUriString("http://www.evail.com\\test.com").build();
//        UriComponents uriString =UriComponentsBuilder.fromUriString("http://www.baiduaa.com/").build();

        String scheme = uriString.getScheme();
        String host = uriString.getHost();
        String path = uriString.getPath();
        String userInfo = uriString.getUserInfo();
        System.out.println("userInfo: " + userInfo);
        System.out.println("scheme : " + scheme);
        System.out.println("host : " + host);
        System.out.println("path : " + path);
    }

    public void testURL(){
        String distance = "";
        String beginPosition = "@baidu.com#";
        String endPosition = "";
        StringBuffer urlStr=new StringBuffer();
        urlStr.append("http://asdsa.com?");
        urlStr.append("origin="+beginPosition+"&destination="+endPosition);
        urlStr.append("&mode=driving&alternatives=false&language=zh-CN&sensor=false");
        connect(urlStr.toString());
    }


    private static void connect(String urlString) {

        try {
            URL url = new URL(urlString); // 设定一个url接口
            httpConn = url.openConnection(); // 链接url地址
            httpConn.setAllowUserInteraction(false);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
